//package com.eolcum.evo.thread;
//
//import java.util.ArrayList;
//import java.util.Calendar;
//import java.util.List;
//
//import com.eolcum.evo.persistence.Apartment;
//import com.eolcum.evo.persistence.Room;
//
//public class OccupancyController implements Runnable {
//
//	private Apartment apartment;
//	
//	private List<Long> roomActivities;
//	private List<Integer> activityRoomIds;
//	private List<Integer> roomIds;
//	
//	private final long occupancyDelay = 300000L;
//	private final long threadCycle = 55000L;
//	
//	@Override
//	public void run() {
//		roomActivities = new ArrayList<Long>();
//		activityRoomIds = new ArrayList<Integer>();
//		roomIds = new ArrayList<Integer>();
//		
//		for(int i = 0; i < apartment.getRooms().size(); i++) {
//			if(apartment.getRooms().get(i).getIsOccupancyControlled().booleanValue() == true) {
//				roomIds.add(apartment.getRooms().get(i).getId());
//			}
//		}
//		
//		//add new occupancy signals
//		while(true) {
//			Long moment = Calendar.getInstance().getTimeInMillis();
//			for(int i = 0; i < roomIds.size(); i++) {
//				Room room = apartment.getRoom(roomIds.get(i));
//				for(int j = 0; j < room.getSensors().size(); j++) {
//					if(room.getSensors().get(j).isActiveOccupied()) {
//						activityRoomIds.add(room.getId());
//						roomActivities.add(moment);
//						break;
//					}
//				}
//			}
//			
//			//Remove old occupancy signals
//			for(int i = 0; i < roomActivities.size(); i++) {
//				if(roomActivities.get(i).compareTo(moment - occupancyDelay) < 0) {
//					roomActivities.remove(i);
//					activityRoomIds.remove(i);
//					i--;
//				}
//			}
//			
//			//Check occupancy
//			for(int i = 0; i < activityRoomIds.size(); i++) {
//				apartment.getRoom(activityRoomIds.get(i)).setActualOccupied(true);
//			}
//			try {
//				Thread.sleep(threadCycle);
//			} catch (InterruptedException e) {}
//		}
//		
//
//	}
//	public Apartment getApartment() {
//		return apartment;
//	}
//	public void setApartment(Apartment apartment) {
//		this.apartment = apartment;
//	}
//
//}
